// electron/preload.js
const { contextBridge, ipcRenderer } = require('electron')
const { electronAPI } = require('@electron-toolkit/preload')

// Custom APIs for renderer
const api = {
 message:() => ipcRenderer.send('message'),
 readFilePath: () => ipcRenderer.invoke('open-file-dialog')
}

const exposeAPIs = () => {
  contextBridge.exposeInMainWorld('electron', {
    ...electronAPI,
    ...api
  })
}

if (process.contextIsolated) {
  try {
    exposeAPIs()
  } catch (error) {
    console.error('Error exposing APIs:', error)
  }
} else {
  // @ts-ignore
  window.electron = { ...electronAPI, ...api }
}
